<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <link href="../css/element.css" rel="stylesheet"/>
    <link href="../css/styleindex.css" rel="stylesheet"/>
    <link href="../css/swiper.min.css" rel="stylesheet"/>
    <style>

    </style>
</head>
<body style="background:#EFF0F4;">

  <div class="mui-content">
    <div id="vm" class="x-examok" v-cloak>
      <div class="x-train-tabs swiper-container">
        <div class="swiper-wrapper">
          <div class="swiper-slide x-train-items" v-for="(item,index) in tabsdata" :key="item.id" @click="changetab(index,item.id)" :class="{active:curId==index}">{{item.title}}</div>
        </div>
      </div>
      <!--  -->
      <div class="x-pro-list" >
        <div class="x-pro-top">问题点</div>
        <div class="" v-for="(item,index) in formdata" :key="item.key" v-if="formdata!=''">
            <div class="x-pro-row">
              <div class="x-pro-label">内容：</div>
              <div class="x-pro-input">
                <el-input placeholder="请输入" v-model="item.content" :disabled="isfromindex"></el-input>
              </div>
            </div>
            <div class="x-pro-row">
              <div class="x-pro-label">改善计划：</div>
              <div class="x-pro-input">
                <el-input placeholder="请输入" v-model="item.improve" :disabled="isfromindex"></el-input>
              </div>
            </div>
            <div class="x-pro-row">
              <div class="x-pro-label">责任人：</div>
              <div class="x-pro-input">
                <el-select v-model="item.set_memberid" placeholder="请选择" :disabled="isfromindex">
                  <el-option v-for="item in persondata" :key="item.id" :label="item.username" :value="item.id"></el-option>
                </el-select>
              </div>
            </div>
            <div class="x-pro-row">
              <div class="x-pro-label">完成时间</div>
              <div class="x-pro-input">
                <el-date-picker v-model="item.finish_time" type="date" placeholder="选择日期"  format="yyyy 年 MM 月 dd 日" value-format="yyyyMMdd"  :disabled="isfromindex" :editable="notkey"></el-date-picker>
              </div>
            </div>
            <div class="x-pro-remove" @click="removeentrywork(index)" v-show="!isfromindex">删除</div>
        </div>
        <div class="x-pro-addbox" @click="addhandwork" v-if="!isfromindex"><span class="x-pro-addicon"></span>添加</div>
      </div>
      <!--  -->
      <div class="x-pro-gobtn" @click="isok" v-show="!isfromindex">提交</div>
    </div>
  </div>

  <script type="text/javascript" src="../script/vue.js"></script>
  <script type="text/javascript" src="../script/element.js"></script>
  <script type="text/javascript" src="../script/api.js"></script>
  <script type="text/javascript" src="../script/base.js"></script>
  <script type="text/javascript" src="../script/swiper.min.js"></script>
	<script>
apiready = function () {
    $api.fixStatusBar($api.byId('header'));


    //
    var vm = new Vue({
      el:'#vm',
      data(){
        return{
          tabsdata:'',
          curId:0,
          tabsid:'',
          formdata:[{
            'content':'',
            'improve':'',
            'memberid':'',
            'finish_time':''
          }],
          persondata:'',
          isfromindex:false,
          notkey:false,
          dutysumindex:0,

        }
      },
      created:function() {
        var that=this;


      },
      mounted:function(){
        var that=this;
        that.getpersondata()
        that.getdata()

      },
      methods: {
        //
        getpersondata:function(){
          let that=this;
          api.ajax({
            url:baseurl+'api/person/list',
            methods:'get',
            data:{
              values:{
                sec: $api.getStorage('apptoken')
              }
            }
          },function(ret,err){
            if(ret){
              api.hideProgress();
              // console.log(JSON.stringify(ret));
              if(ret.status == 1){
                that.persondata = ret.data.list;

              }else{
                api.toast({
                    msg: ret.msg,
                    duration: 3000,
                    location: 'bottom'
                });
              }
            }else{
              api.hideProgress();
              console.log(JSON.stringify(err));
              api.toast({
                  msg: err.msg,
                  duration: 3000,
                  location: 'bottom'
              });
            }
          })
        },
        changetab:function(index,id){
          var that = this;
          that.curId = index;
          that.tabsid = id;
          that.getdata()
        },
        //
        getdata:function(){
          let that=this;
          console.log(that.tabsid);
          api.ajax({
            url:baseurl+'api/duty/getCheckSummary',
            methods:'get',
            data:{
              values:{
                sec: $api.getStorage('apptoken'),
                cateid:that.tabsid
              }
            }
          },function(ret,err){
            if(ret){
              api.hideProgress();
              console.log(JSON.stringify(ret));
              if(ret.status == 1){
                  that.tabsdata = ret.data.cate;
                  that.formdata = ret.data.list;
                  that.tabsid = ret.data.cate[0].id;
                  var numm;
                  if(ret.data.cate.length<3){
                    numm = 2;
                  }else{
                    numm = 3;
                  }
                  that.$nextTick(function(){
                    var mySwiper = new Swiper('.swiper-container',{
                      freeMode: true,
                      loop:false,//设置 active slide 居中后，会有左右留白现象，添加此会让未尾的导航补齐前后空白
                      slideToClickedSlide: true,//设置为true则点击slide会过渡到这个slide。
                      slidesPerView: numm,
                      centeredSlides: false,//设定为true时，active slide会居中，而不是默认状态下的居左。
                      spaceBetween: 10,//slide之间设置距离
                      slidesOffsetBefore: 0,//设定slide与左边框的预设偏移量
                      slidesOffsetAfter: 0,//设定slide与右边框的预设偏移量

                    });

                  });
              }else{
                api.toast({
                    msg: ret.msg,
                    duration: 3000,
                    location: 'bottom'
                });
              }
            }else{
              api.hideProgress();
              console.log(JSON.stringify(err));
              api.toast({
                  msg: err.msg,
                  duration: 3000,
                  location: 'bottom'
              });
            }
          })
        },
        //
        isok:function(){
          var that = this;
          console.log(that.tabsid);
          console.log(JSON.stringify(that.formdata));
          api.ajax({
            url:baseurl+'api/duty/setCheckSummary',
            methods:'get',
            data:{
              values:{
                sec: $api.getStorage('apptoken'),
                cateid:that.tabsid,
                check_json:JSON.stringify(that.formdata)
              }
            }
          },function(ret,err){
            if(ret){
              api.hideProgress();
              console.log(JSON.stringify(ret));
              if(ret.status == 1){
                api.alert({
                    title: '提交成功',
                    msg: '',
                }, function(ret, err) {

                });

              }else{
                api.toast({
                    msg: ret.msg,
                    duration: 3000,
                    location: 'bottom'
                });
              }
            }else{
              api.hideProgress();
              console.log(JSON.stringify(err));
              api.toast({
                  msg: err.msg,
                  duration: 3000,
                  location: 'bottom'
              });
            }
          })
        },
        //添加
        addhandwork:function(){
          var that = this;
          that.dutysumindex++
          that.formdata.push({
            'content':'',
            'improve':'',
            'memberid':'',
            'finish_time':'',
            'index':that.dutysumindex
          })
        },
        //删除
        removeentrywork:function(index){
          let that = this;
          var nowin = index;
          console.log(JSON.stringify(that.formdata));
          api.confirm({
            title: '操作提示',
            msg: '确定要删除吗？',
            buttons: ['确定','取消']
          }, function(ret, err) {
            var index = ret.buttonIndex;
            if(index == 1){
              //删除
              that.formdata.splice(nowin,1);//删除全部数组中对应的值
              console.log(JSON.stringify(that.formdata));
            }
          });
        },
      }
    })
	}


	</script>
</body>
</html>
